package com.treasure.mall.biz.repository.order;

import com.treasure.mall.biz.base.JpaSearchableRepository;
import com.treasure.mall.biz.entity.order.SettlementBillPO;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/7/23
 */
@Repository
public interface SettlementBillRepository extends JpaSearchableRepository<SettlementBillPO, String> {
    SettlementBillPO findByOrderItemId(Long itemId);

    List<SettlementBillPO> findBySubOrderId(String subOrderId);

    /**
     * 未失效并且未转正的
     *
     * @return
     */
    List<SettlementBillPO> findByInvalidateIsFalseAndConvertedIsFalseAndConvertTimeLessThanEqual(LocalDateTime time);


    /**
     * 修改结算单是否失效
     * 产生售后行为时，设置为失效true，售后拒绝或取消售后设置为false
     *
     * @param orderItemId
     * @param invalidate
     */
    @Query("update SettlementBillPO set invalidate =?2 where orderItemId=?1")
    @Modifying
    @Transactional
    void modifyInvalidate(Long orderItemId, boolean invalidate);
}
